
/*
 * Copyright 2002-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2021原作者。
 *
 *根据Apache许可证2.0版（“许可证”）许可；
 *除非符合许可证的规定，否则您不得使用此文件。
 *您可以在以下网址获取许可证副本
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，否则软件
 *根据许可证分发是在“按原样”的基础上分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限的特定语言，请参阅许可证
 *许可证下的限制。
 */

package org.springframework.context;

import java.time.Clock;
import java.util.EventObject;

/**
 * Class to be extended by all application events. Abstract as it
 * doesn't make sense for generic events to be published directly.
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @see org.springframework.context.ApplicationListener
 * @see org.springframework.context.event.EventListener
 */
/**
 *要由所有应用程序事件扩展的类。尽管如此抽象
 *直接发布一般事件是没有意义的。
 *
 *@作者罗德·约翰逊
 *@作者Juergen Hoeller
 *@参见org.springframework.context.ApplicationListener
 *@参见org.springframework.context.event.EventListener
 */
public abstract class ApplicationEvent extends EventObject {

	/** use serialVersionUID from Spring 1.2 for interoperability. */
	private static final long serialVersionUID = 7099057708183571937L;

	/** System time when the event happened. */
	private final long timestamp;


	/**
	 * Create a new {@code ApplicationEvent} with its {@link #getTimestamp() timestamp}
	 * set to {@link System#currentTimeMillis()}.
	 * @param source the object on which the event initially occurred or with
	 * which the event is associated (never {@code null})
	 * @see #ApplicationEvent(Object, Clock)
	 */
	/** use serialVersionUID from Spring 1.2 for interoperability. */
	私有静态最终长序列版本UID=7099057708183571937L；

	/**事件发生的系统时间*/
	私有最终长时间戳；


	/**
	 *创建一个新的｛@code ApplicationEvent｝及其｛@link#getTimestamp（）时间戳｝
	 *设置为{@link System#currentTimeMillis（）}。
	 *@param source事件最初发生的对象或与
	 *与事件关联的（从不｛@code null｝）
	 *@see#ApplicationEvent（对象，时钟）
	 */
	public ApplicationEvent(Object source) {
		super(source);
		this.timestamp = System.currentTimeMillis();
	}

	/**
	 * Create a new {@code ApplicationEvent} with its {@link #getTimestamp() timestamp}
	 * set to the value returned by {@link Clock#millis()} in the provided {@link Clock}.
	 * <p>This constructor is typically used in testing scenarios.
	 * @param source the object on which the event initially occurred or with
	 * which the event is associated (never {@code null})
	 * @param clock a clock which will provide the timestamp
	 * @since 5.3.8
	 * @see #ApplicationEvent(Object)
	 */
	/**
	 *创建一个新的｛@code ApplicationEvent｝及其｛@link#getTimestamp（）时间戳｝
	 *设置为提供的｛@link Clock｝中的｛@link Clock#millis（）｝返回的值。
	 *<p>此构造函数通常用于测试场景。
	 *@param source事件最初发生的对象或与
	 *与事件关联的（从不｛@code null｝）
	 *@param clock将提供时间戳的时钟
	 *@自5.3.8起
	 *@see#ApplicationEvent（对象）
	 */
	public ApplicationEvent(Object source, Clock clock) {
		super(source);
		this.timestamp = clock.millis();
	}


	/**
	 * Return the time in milliseconds when the event occurred.
	 * @see #ApplicationEvent(Object)
	 * @see #ApplicationEvent(Object, Clock)
	 */
	/**
	 *返回事件发生时的时间（以毫秒为单位）。
	 *@see#ApplicationEvent（对象）
	 *@see#ApplicationEvent（对象，时钟）
	 */
	public final long getTimestamp() {
		return this.timestamp;
	}

}
